package com.scpii.universal.test;

import java.util.List;

import com.scpii.universal.client.Client;
import com.scpii.universal.pb.PbUniversal.PBCMD;
import com.scpii.universal.pb.PbUniversal.PBContentSearchCS;
import com.scpii.universal.pb.PbUniversal.PBContentSearchFieldCS;
import com.scpii.universal.pb.PbUniversal.PBContentSearchFieldSC;
import com.scpii.universal.pb.PbUniversal.PBContentSearchSC;
import com.scpii.universal.pb.PbUniversal.PBHouseContentDetailCS;
import com.scpii.universal.pb.PbUniversal.PBHouseContentDetailSC;
import com.scpii.universal.pb.PbUniversalBasic.PbAppPageContent;
import com.scpii.universal.pb.PbUniversalBasic.PbAppPageContentList;
import com.scpii.universal.pb.PbUniversalBasic.PbContentImg;
import com.scpii.universal.pb.PbUniversalBasic.PbContentImgList;
import com.scpii.universal.pb.PbUniversalBasic.PbEnterpShop;
import com.scpii.universal.pb.PbUniversalBasic.PbEnterpShopList;
import com.scpii.universal.pb.PbUniversalBasic.PbForSearchField;
import com.scpii.universal.pb.PbUniversalBasic.PbForSearchFieldList;
import com.scpii.universal.pb.PbUniversalBasic.PbSearchField;
import com.scpii.universal.pb.PbUniversalBasic.PbSearchFieldBasic;
import com.scpii.universal.pb.PbUniversalBasic.PbSearchFieldList;
import com.scpii.universal.pb.PbUniversalBasic.PbSelectOption;
import com.scpii.universal.pb.PbUniversalBasic.PbSelectOptionList;

public class HouseContentEntrance {
	public static void PBHouseContentDetailCMD() throws Exception {
		PBHouseContentDetailCS.Builder pBHouseContentDetailCS = PBHouseContentDetailCS.newBuilder();//请求参数
		pBHouseContentDetailCS.setIntAppId(1060);
		pBHouseContentDetailCS.setIntContentId(1075);
		
		byte[] bytes = pBHouseContentDetailCS.build().toByteArray();
		byte[] returnBytes = Client.testPOSTMethod(PBCMD.PBHouseContentDetailCMD.getNumber(), bytes);
		if (returnBytes!=null && returnBytes.length>0) {
			PBHouseContentDetailSC pBHouseContentDetailSC = PBHouseContentDetailSC.parseFrom(returnBytes);
			System.out.println("执行结果："+pBHouseContentDetailSC.getExeResult().toString());
			
			//详情URL
			System.out.println("详情URL："+pBHouseContentDetailSC.getVarDetailUrl());
			//联系我们电话
			System.out.println("联系我们电话："+pBHouseContentDetailSC.getVarPhoneNum());
			
			System.out.println("-------------地图导航---------------------");
			//地图导航
			PbEnterpShopList pbEnterpShopList = pBHouseContentDetailSC.getPbEnterpShopList();
			List<PbEnterpShop> enterpShopList = pbEnterpShopList.getPbEnterpShopListList();
			if (enterpShopList!=null && enterpShopList.size()>0) {
				for (PbEnterpShop pbEnterpShop : enterpShopList) {
					System.out.println(pbEnterpShop.getIntAppId());
					System.out.println(pbEnterpShop.getIntEnterpId());
					System.out.println(pbEnterpShop.getIntShopId());
					
					System.out.println("地址："+pbEnterpShop.getVarShopAddress());
					System.out.println("门店名称："+pbEnterpShop.getVarShopName());
					System.out.println("省份："+pbEnterpShop.getVarShopProvince());
					System.out.println("纬度："+pbEnterpShop.getVarShopLatitude());
					System.out.println("经度："+pbEnterpShop.getVarShopLongitude());
				}
			}
			
			System.out.println("-----------相册---------------------");
			//相册
			PbContentImgList pbImgListBuilder = pBHouseContentDetailSC.getPbContentImgList();
			List<PbContentImg> lstImgs = pbImgListBuilder.getPbContentImgListList();
			if(lstImgs!=null && lstImgs.size()>0){
				for (PbContentImg pbContentImg : lstImgs) {
					System.out.println("图片ID："+pbContentImg.getIntImgId());
					System.out.println("图片URL："+pbContentImg.getVarImgUrl());
				}
			}
		}
	}
	
	public static void PBContentSearchCMD() throws Exception {
		PBContentSearchCS.Builder pBContentSearchCS = PBContentSearchCS.newBuilder();//请求参数
		pBContentSearchCS.setIntAppId(1676);
		pBContentSearchCS.setVarKeyWord("搜索");
		pBContentSearchCS.setPageNo(1);
//		PbSearchFieldList.Builder pbSearchFieldList = PbSearchFieldList.newBuilder();
//		PbSearchField.Builder pbSearchField1 = PbSearchField.newBuilder();
//		PbSearchFieldBasic.Builder pbSearchFieldBasic1 = PbSearchFieldBasic.newBuilder();
//		pbSearchFieldBasic1.setIntAttrId(2162);
//		pbSearchFieldBasic1.setIntAttrType(1);
//		pbSearchField1.setPbSearchFieldBasic(pbSearchFieldBasic1);
//		pbSearchField1.setVarAttrValue("133");
//		pbSearchFieldList.addPbSearchField(pbSearchField1);
		
//		PbSearchField.Builder pbSearchField2 = PbSearchField.newBuilder();
//		PbSearchFieldBasic.Builder pbSearchFieldBasic2 = PbSearchFieldBasic.newBuilder();
//		pbSearchFieldBasic2.setIntAttrId(1468);
//		pbSearchFieldBasic2.setIntAttrType(1);
//		pbSearchField2.setPbSearchFieldBasic(pbSearchFieldBasic2);
//		pbSearchField2.setVarAttrValue("44");
//		pbSearchFieldList.addPbSearchField(pbSearchField2);
		
//		PbSearchField.Builder pbSearchField3 = PbSearchField.newBuilder();
//		PbSearchFieldBasic.Builder pbSearchFieldBasic3 = PbSearchFieldBasic.newBuilder();
//		pbSearchFieldBasic3.setIntAttrId(1469);
//		pbSearchFieldBasic3.setIntAttrType(1);
//		pbSearchField3.setPbSearchFieldBasic(pbSearchFieldBasic3);
//		pbSearchField3.setVarAttrValue("138");
//		pbSearchFieldList.addPbSearchField(pbSearchField3);
		
//		pBContentSearchCS.setPbSearchFieldList(pbSearchFieldList);
		
		byte[] bytes = pBContentSearchCS.build().toByteArray();
		byte[] returnBytes = Client.testPOSTMethod(PBCMD.PBContentSearchCMD.getNumber(), bytes);
		if (returnBytes!=null && returnBytes.length>0) {
			PBContentSearchSC pBContentSearchSC = PBContentSearchSC.parseFrom(returnBytes);
			System.out.println("执行结果："+pBContentSearchSC.getExeResult().toString());
			
			PbAppPageContentList pbAPConList = pBContentSearchSC.getPbAppPageContentList();
			List<PbAppPageContent> pbAPCList = pbAPConList.getPbAppPageContentList();
			System.out.println("搜索记录条数:"+pbAPCList.size());
			if (pbAPCList!=null && pbAPCList.size()>0) {
				for (PbAppPageContent pbAPCon : pbAPCList) {
					System.out.println("分类ID:"+pbAPCon.getIntCateId());
					System.out.println("内容ID:"+pbAPCon.getIntContentId());
					
					System.out.println("名称:"+pbAPCon.getVarContentName());
					System.out.println("缩略图:"+pbAPCon.getVarContentImgUrl());
					System.out.println("描述:"+pbAPCon.getVarContentDescrip());
					System.out.println("详情页面类型："+pbAPCon.getIntDetailPageType());
				}
			}
		}
	}
	
	public static void PBContentSearchField() throws Exception {
		PBContentSearchFieldCS.Builder pBContentSearchFieldCS = PBContentSearchFieldCS.newBuilder();//请求参数
		pBContentSearchFieldCS.setIntAppId(1289);
		
		byte[] bytes = pBContentSearchFieldCS.build().toByteArray();
		byte[] returnBytes = Client.testPOSTMethod(PBCMD.PBContentSearchField.getNumber(), bytes);
		if (returnBytes!=null && returnBytes.length>0) {
			PBContentSearchFieldSC pBContentSearchFieldSC = PBContentSearchFieldSC.parseFrom(returnBytes);
			System.out.println("执行结果："+pBContentSearchFieldSC.getExeResult().toString());
			
			PbForSearchFieldList pbForSearchFieldList = pBContentSearchFieldSC.getPbForSearchFieldList();
			List<PbForSearchField> pbFieldList = pbForSearchFieldList.getPbForSearchFieldList();
			if (pbFieldList!=null && pbFieldList.size()>0) {
				for (PbForSearchField field : pbFieldList) {
					PbSearchFieldBasic pbSearchFieldBasic = field.getPbSearchFieldBasic();
					System.out.println("属性ID:"+pbSearchFieldBasic.getIntAttrId());
					System.out.println("属性输入类型:"+pbSearchFieldBasic.getIntAttrType());
					System.out.println("属性名:"+field.getVarAttrName());
					PbSelectOptionList pbSelectOptionList = field.getPbSelectOptionList();
					List<PbSelectOption> options = pbSelectOptionList.getPbSelectOptionList();
					System.out.println("选项-----------------------");
					for (PbSelectOption option : options) {
						System.out.println("选项Key:"+option.getOptionKey());
						System.out.println("选项值:"+option.getOptionValue());
					}
					System.out.println("-----------------------------------------------------------");
				}
			}
		}
	}

	public static void main(String[] args) {
		try {
//			PBHouseContentDetailCMD();
			PBContentSearchCMD();
//			PBContentSearchField();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
